#include "net.h"
#include <string.h>

returnType N_readServerMessages(void *n_void) {
    struct Net *n = n_void;
    while(n->active) {
        struct Package pkg = N_get(n);
        if(n->pkgCount >= MAX_PKG_COUNT)
            n->pkgCount = MAX_PKG_COUNT-1;
        memcpy(&n->pkgList[++(n->pkgCount)], &pkg, sizeof(struct Package));
    }
    return(0);
}

void N_popPkg(struct Net *n, struct Package *pkg) {
    if(n == NULL) return;
    if(n->pkgCount > MAX_PKG_COUNT)
        n->pkgCount = MAX_PKG_COUNT;
    if(n->pkgCount < 0)
        pkg = NULL;
    memcpy(pkg, &n->pkgList[n->pkgCount], sizeof(struct Package));
    n->pkgCount--;
    if(n->pkgCount < 0) n->pkgCount = 0;
}
